package com.godpaper.as9.commands
{
	import com.adobe.cairngorm.commands.ICommand;
	import com.adobe.cairngorm.control.CairngormEvent;
	import com.godpaper.as9.bussiness.delegates.AlbumDelegate;
	import com.godpaper.as9.events.GetAlbumListEvent;
	import com.godpaper.as9.model.AlbumModelLocator;
	import com.godpaper.as9.vo.AlbumVO;
	
	import mx.rpc.IResponder;

	public class GetAlbumListCommand extends CommandBase implements ICommand, IResponder
	{
		private var delegate:AlbumDelegate;
		private var albumModel:AlbumModelLocator = AlbumModelLocator.getInstance();
		private var getAlbumInfoEvent:GetAlbumListEvent;

		public function GetAlbumListCommand()
		{
			super();
			delegate = new AlbumDelegate(this);
		}
		
		override public function execute(event:CairngormEvent):void
		{
			getAlbumInfoEvent = GetAlbumListEvent(event);
			delegate.read(null);
		}
		
		override public function result(data:Object):void
		{
			albumModel.albumList.disableAutoUpdate();
			albumModel.albumList.removeAll();
			
			if(data.hasOwnProperty("result"))
			{
				if(data.result)
				{
					for(var i:int=0;i<data.result.length;i++)
					{
						var vo:AlbumVO = new AlbumVO();
						vo.ano = data.result[i].ano;
						vo.capcity = data.result[i].capcity;
						vo.cno = data.result[i].cno;
						vo.created_time = data.result[i].created_time;
						vo.creator = data.result[i].creator;
						vo.description = data.result[i].description;
						vo.name = data.result[i].name;
						vo.thumbnail = data.result[i].thumbnail;
						vo.used = data.result[i].used;
						vo.browsed = data.result[i].browsed;
						
						albumModel.albumList.addItem(vo);
					}
				}
			}
			
			albumModel.albumList.enableAutoUpdate();
			albumModel.albumList.refresh();
			
		}
		
		
	}
}